package com.zhiyou100.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.IService.Iservice;
import com.zhiyou100.entity.ProsGyzc;
import com.zhiyou100.entity.prosGo.TbProjects;
import com.zhiyou100.entity.prosGo.TbUser;


@Controller
public class GyzcController {
	
	@Resource
	private Iservice service;
	@Autowired
	private HttpServletRequest request;
	
	private Integer save;
	
	@RequestMapping("selectGyzc.do")
	public String selectGyzc(@RequestParam(required=true,defaultValue="1")Integer page,ProsGyzc p,Integer go) {
		PageHelper.startPage(page,8);
		if (go!=null&&go==1) {
			save=p.getPsPstId();
		}
		if (go==null) {
			p.setPsPstId(save);
		}
		List<ProsGyzc> list =  service.selectGyzc(p);
		PageInfo<ProsGyzc> p1 = new PageInfo<ProsGyzc>(list);
		request.setAttribute("page", p1);
		request.setAttribute("pros", list);
		String s = "selectGyzc.do";
		request.setAttribute("select", s);
		return "gyzc-list";
	}
	
	@RequestMapping("selectByType.do")
	public String selectByType(@RequestParam(required=true,defaultValue="1")Integer page,ProsGyzc p,Integer go) {
		PageHelper.startPage(page,8);
		if (go!=null&&go==1) {
			save=p.getPsType();
		}
		if (go==null) {
			p.setPsType(save);
		}
		List<ProsGyzc> list = service.selectByType(p);
		PageInfo<ProsGyzc> p1 = new PageInfo<ProsGyzc>(list);
		request.setAttribute("page", p1);
		request.setAttribute("pros", list);
		String s = "selectByType.do";
		request.setAttribute("select", s);
		return "gyzc-list";
	}
	@RequestMapping("order.do")
	public String order(@RequestParam(required=true,defaultValue="1")Integer page,Integer go,Integer num) {
		List<ProsGyzc> list = new ArrayList<ProsGyzc>();
		PageHelper.startPage(page,8);
		if (go!=null&&go==1) {
			save=num;
		}
		if (go==null) {
			num=save;
		}
		list = service.order(num);
		PageInfo<ProsGyzc> p1 = new PageInfo<ProsGyzc>(list);
		request.setAttribute("page", p1);
		request.setAttribute("pros", list);
		String s = "order.do";
		request.setAttribute("select", s);
		return "gyzc-list";
	}
	@RequestMapping("product-detail.do")
	public String pdet(TbProjects pro) {
		TbProjects p = service.selectGyzcOne(pro);
		TbUser uss = service.selectus(p.getPsUsId());
		request.setAttribute("pro", p);
		request.setAttribute("us", uss);
		return "product-detail";
	}
}
